﻿using System;
using com.IronOne.BoardPACWinAppBO.Auth;
using com.IronOne.BoardPACWinAppBO.General;
using com.IronOne.BoardPACWinAppDAO.DB;
using com.IronOne.BoardPACWinAppUtil.Util;

namespace com.IronOne.BoardPACWinAppDAO.Mapper
{
    internal class ModelToEntityMapper
    {
        public static User UserModelToEntity(UserModel userModel, User userEntity)
        {
            try
            {
                userEntity.UserId = userModel.UserId;
                userEntity.UserName = userModel.UserName;
                userEntity.UserFullName = userModel.UserFullName;
                userEntity.iPadDisplayName = userModel.IPadDisplayName;
                userEntity.Password = userModel.Password;
                userEntity.PasswordSalt = userModel.PasswordSalt;

                return userEntity;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static User UserModelToEntity(UserModel userModel)
        {
            try
            {
                var userEntity = new User
                {
                    UserId = userModel.UserId,
                    UserName = userModel.UserName,
                    UserFullName = userModel.UserFullName,
                    iPadDisplayName = userModel.IPadDisplayName,
                    Password = userModel.Password
                };

                return userEntity;
            }
            catch (Exception)
            {
                throw;
            }
        }

        internal static Log LogDataModelToEntity(LogDataModel ldm)
        {
            try
            {
                var log = new Log
                {
                    Action = ldm.Action,
                    Data = ldm.Data,
                    Date = DateTime.Now,
                    LastUpdatedDateTime = DateTime.Now,
                    MeetingID = ldm.MeetingId,
                    MemberId = Global.UserId,
                    PaperID = ldm.PaperId,
                    Info = ldm.Info,
                    UpdateID = new Random().Next().ToString()
                };
                //log.Info = 
                //log.LastUpdatedTimeStamp = ldm
                //log.LogId = ldm
                //log.Status = ldm

                return log;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        ///     Assign 2nd object "entity" to forst object "log"
        /// </summary>
        /// <param name="log"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        internal static Log MapLogDataModelForUpdate(Log log, Log entity)
        {
            try
            {
                //log.Action = entity.Action;
                log.Data = entity.Data;
                log.Info = entity.Info;
                //log.Date = DateTime.Now;
                log.LastUpdatedDateTime = DateTime.Now;
                //log.MeetingID = entity.MeetingID;
                //log.MemberId = Global.UserId;
                //log.PaperID = entity.PaperID;
                log.UpdateID = new Random().Next().ToString();

                return log;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}